package com.zfl.thread.day01;

import lombok.AllArgsConstructor;
import lombok.Data;

@AllArgsConstructor
@Data
class BankCount {
    private int balance;
    private String id;

    public void withdraw(int money){
        if(balance-money<0){
            System.out.println(Thread.currentThread().getName()+"取款失败，余额为["+this.balance+"]");
        } else{
            this.balance -= money;
            System.out.println(Thread.currentThread().getName()+"取款"+money+"余额为["+this.balance+"]");
        }

    }

    public void deposit(int money){
        balance+=money;
        System.out.println(Thread.currentThread().getName()+"存款"+money+"余额为["+balance+"]");
    }
}

public class Demo06 {

    public static void main(String[] args) {
        BankCount count = new BankCount(1000,"zfl");
        new Thread(()->{
            for (int i = 0; i < 20; i++) {
                count.withdraw(300);
            }
        },"取款").start();
        new Thread(()->{
            for (int i = 0; i < 20; i++) {
                count.deposit(200);
            }
        },"取款").start();
    }


}
